import Lava
import Lava.Patterns
import Lava.Arithmetic
 
type Bit = Signal Bool
type Binary = [Bit]
 
--A1
binAdder1 :: (Binary,Binary) -> Binary
binAdder1 (a:as, b:bs) = [s] ++ sum ++ [carryOut]
    where
    (sum,carryOut) = adder(c0,(as,bs));
    (s,c0) = halfAdd(a,b);
 
     
--new testing

binary_inputs_A1 =[ (((int2bin 4) x),((int2bin 4) y)) | x<-[0..15],y<-[0..15]]

test_ex_A1_0 = simulateSeq binAdder1 binary_inputs_A1 

results_in_integer_A1 =simulateSeq bin2int(test_ex_A1_0)
 

-- previous testing
testA1 :: (Num t) => t -> (Signal Int, Signal Int) -> Signal Int
testA1 n (a,b) = out
 where
  as = int2bin n a
  bs = int2bin n b
  sum  = binAdder1 (as,bs)
  out  = bin2int(sum)
 
arrayA1 = [ (x,y) | x<-[0..15],y<-[0..15]]
 
test1=simulateSeq (testA1 4) [(4,4),(4,5),(0,0),(0,1),(1,0),(3,5),(4,6),(6,6),(7,7),(8,8),(9,9)]
 
test_ex_A1_1=simulateSeq (testA1 4) arrayA1

